* --------------------- *
* This file loads the child level data to compute summary statistics presented in Tables 2 and 3.
* Author: Victor Ronda
* Date Created: 01 Mar 2020
* Last Update: 22 Jan 2023
* --------------------- *


clear all
set more off

************************************
*** Summary Statistics - Table 3 ***
************************************

use  "offspring_data.dta"

gen prim=0 if preg~=.
replace prim=1 if preg==1

replace stillborn=0 if stillborn==.

foreach var of varlist bw diedb1m {
replace `var'=. if stillborn==1
}

local outcomes1 "stillborn diedb1m bw"

local controls1 "female"
local controls2 "mom_cohort female mom_primip"

gen r_inte=0 if rear_inte==0|rear_inte==2
replace r_inte=1 if rear_inte==1|rear_inte==3
gen r_inte_MR=0 if rear_inte==0
replace r_inte_MR=1 if rear_inte==1
gen r_inte_PR=0 if rear_inte==2
replace r_inte_PR=1 if rear_inte==3

gen r_intra=0 if rear_inte==0|rear_inte==1
replace r_intra=1 if rear_inte==2|rear_inte==3
gen r_intra_MR=0 if rear_inte==0
replace r_intra_MR=1 if rear_inte==2
gen r_intra_PR=0 if rear_inte==1
replace r_intra_PR=1 if rear_inte==3

gen r1= mom_rear_MR_SPR
gen r2=r_inte_MR
gen r3=r_inte_PR
gen r4=r_intra
gen r5=r_intra_MR
gen r6=r_intra_PR

rename health_issue_*_10m3y hi_*_13
replace hi_m_13=1-hi_m_13
replace hi_m_13=. if obs_10m3y<=5

rename dominance* dom*
rename dom_relative_rank dom_pct

drop if mom_cohort==. | female==. | mom_primip==. | cohort==. | primip==. |mom_rear_MR_SPR==. 

**********************
****** Table 2 *******
**********************

tab r_inte r_intra, cell

**********************
****** Table 3 *******
**********************

gen livebirth=1-stillborn
gen survived1m=1-diedb1m

	* First 5 columns of Table 3:
sum livebirth survived1m bw
sum hi_m_13 dom_pct if  rear_inte~=.
	* Last 3 columns of Table 3:
sum female mom_rear_MR if livebirth ~=.
sum female rear_MR mom_rear_MR if survived1m ~=.
sum female rear_MR mom_rear_MR if bw~=.
sum female rear_MR mom_rear_MR if hi_m_13~=. & rear_inte~=.
sum female rear_MR mom_rear_MR if dom_pct~=. & rear_inte~=.
